U64 stats_net_dev_last_time = 0;  //us
struct stats_net_dev stats_net_dev_last[SV_MAX_DATANICS];
U64 nic_flow_now[SV_MAX_DATANICS];

int get_nic_flow(int first_flag)
{
	int i, j;
	struct stats_net_dev stats_net_dev_curr[MAX_NIC_NUM_IN_MACHINE];
	int nic_num_in_machine = 0;
	U64 stats_net_dev_curr_time = 0;  //us
	
	memset(stats_net_dev_curr, 0, sizeof(stats_net_dev_curr));
	
	nic_num_in_machine = read_net_dev(stats_net_dev_curr, MAX_NIC_NUM_IN_MACHINE, &stats_net_dev_curr_time);

	if (nic_num_in_machine <= 0)
	{
		if (nic_num_in_machine == ECOUNTOVER)
		{
			MNG_FATAL("nic num is over %d", MAX_NIC_NUM_IN_MACHINE);
		}
		else if (nic_num_in_machine == 0)
		{
			MNG_FATAL("nic num is 0");
		}
		
		return -1;
	}
	
	for (i = 0;i < g_sv_conf.nic_count; i++)
	{
		for (j = 0;j < nic_num_in_machine; j++)
		{
			if (!strcmp(stats_net_dev_last[i].interface, stats_net_dev_curr[j].interface))
			{
				if (first_flag == 0)
				{
					if ((stats_net_dev_curr[j].tx_bytes > stats_net_dev_last[i].tx_bytes) 
						&& (stats_net_dev_curr_time > stats_net_dev_last_time))
					{
						/*
						tx: Byte; tm: us
						nic_flow = (tx2 - tx1) / (tm2 - tm1) * 1000000  ==> get Bytes per second
						nic_flow = (tx2 - tx1) / (tm2 - tm1) * 1000000 * 8  ==> get bits per second
						nic_flow = (tx2 - tx1) / (tm2 - tm1) * 1000000 * 8 / 1000000 ==> get Mbits per second, so this is
						equal to nic_flow = (tx2 - tx1) / (tm2 - tm1) * 8 ==> get Mbits per second
						*/
						nic_flow_now[i] = (stats_net_dev_curr[j].tx_bytes - stats_net_dev_last[i].tx_bytes) * 8 / 
											(stats_net_dev_curr_time - stats_net_dev_last_time);  //Mbps
					}
					else
					{
						nic_flow_now[i] = 0;
					}
				}

				stats_net_dev_last[i] = stats_net_dev_curr[j];
				
				break;
			}
		}
	}

	stats_net_dev_last_time = stats_net_dev_curr_time;
	
	return 0;
}

int main(int argc, char **argv)
{
	
}